import React from 'react';

import {Route, Switch, withRouter} from 'react-router-dom';
import routes from './routeConfig';

function RouteComponent() {
    return (
        <div>
            <div className="body-content">
                <div className="route-content">
                    <Switch>
                        {
                            routes&&routes.length>0 ? routes.map((route: any, index: number) => {
                            return  <RouteWithSubRoutes key={index} {...route} />
                            })
                            : ''
                        }
                    </Switch>
                </div>
            </div>
        </div>
    )
}
const RouteWithSubRoutes = (route:any): any => {
 
    return (
        <Route
            path={route.path}
            render={props => {
                return <route.component {...props} children={route.children} />
            }}
        />
    )
};

export default withRouter(RouteComponent)